<?php

App::import('Vendor', 'lastRSS', array('file'=>'lastRSS.php'));

class RssHelper extends Helper {

	var $helpers = array("Html");

	function latestPosts($feed, $number) {

		// Create lastRSS object 
		$rss = new lastRSS; 
		
		// Set cache dir and cache time limit (1200 seconds) 
		// (don't forget to chmod cahce dir to 777 to allow writing) 
		$rss->cache_dir = './temp'; 
		$rss->cache_time = 1200; 
		
		$output = '';
		
		// Try to load and parse RSS file 
		if ($rs = $rss->get($feed)) { 
		    // Show clickable website title 
		    for($i = 0; $i < $number; $i++) { 
		        $output .= "<p><a href=\"" . $rs['items'][$i]['link'] . "\">" . $rs['items'][$i]['title'] . "</a></p>\n"; 
		        } 
		    } 
		else { 
		    $output .= "Error: It's not possible to reach RSS file...\n"; 
		}
		return $output;
	}
}
